function distributeTask(assistId, instruction, callback) {
    var type = 1;
    var postData = {
        'content': instruction,
        'type': type,
        'id': assistId
    };
    console.log(instruction);
    $.ajax({
        type: "POST",
        async: false,
        url: moduleUrl + 'Service/distributeTask',
        contentType: "application/x-www-form-urlencoded",
        dataType: "json",
        data: postData,
        success: function (data, textStatus, xhr) {
            if (xhr.status === 200) {
                var taskId = data;
                if (taskId !== null && taskId.length === 24) {
                    console.log(taskId);
                    //回调
                    callback(taskId);
                    return taskId;
                }
            } else {
                $.messager.show({
                    title: 'Error',
                    msg: data.msg
                });
            }
        }

    });
}

function flashTaskStatus(assistId, taskId, callback) {
    $.ajax({
        type: "GET",
        url: moduleUrl + 'Service/getTaskInfo?assistId=' + assistId + '&taskId=' + taskId,
        contentType: "application/json",
        dataType: "json",
        success: function (data, textStatus, xhr) {
            if (xhr.status === 200) {
                callback(data);
            } else {
                $.messager.show({
                    title: 'Error',
                    msg: data.msg
                });
            }
        }

    });
}

function getAliveAssist(assistId, alive, callback) {
    // console.log(assistId);
    $.ajax({
        type: "GET",
        url: moduleUrl + 'Service/getAssistAlive?assistId=' + assistId,
        contentType: "application/json",
        dataType: "json",
        success: function (data, textStatus, xhr) {
            if (xhr.status === 200) {

                if (data === 200) {
                    // $('#device_alive').attr('style', 'color: #00ee00;font-weight: bold;display: inline-block');
                    alive.replaceWith('<li id="device_alive" style="color: #00ee00;font-weight: bold;display: inline-block" >设备在线</li>');
                } else if (data === 203) {
                    console.log("失败");
                    alive.replaceWith('<li id="device_alive" style="color: #dc372d;font-weight: bold;display: inline-block" >设备掉线</li>');
                } else if (data === 204) {
                    //协助退出
                    callback();
                    alive.text('');
                    $('#assist_state').text('完成');
                }

            } else {
                $.messager.show({
                    title: 'Error',
                    msg: data.msg
                });
            }
        }

    });

}
function assistQuit(assistId, callback) {
    if (confirm('确认退出？')) {
        $('#assist_quit').attr('hidden', 'hidden');
        $.ajax({
            type: "GET",
            url: moduleUrl + 'Service/quitAssistance?assistId=' + assistId,
            contentType: "application/json",
            dataType: "json",
            success: function (data, textStatus, xhr) {
                if (xhr.status === 200) {
                    callback(data);
                } else {
                    $.messager.show({
                        title: 'Error',
                        msg: data.msg
                    });
                }
            }

        });
    }

}


/*获取url参数*/
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var url = decodeURI(decodeURI(window.location.search))
    var r = url.substr(1).match(reg);
    if (r !== null) return unescape(r[2]);
    return null;
}
//获取协助状态
function removeAllSpace(str) {
    return str.replace(/\s+/g, "");
}

String.prototype.endWith = function (s) {
    if (s === null || s === "" || this.length === 0 || s.length > this.length)
        return false;
    return this.substring(this.length - s.length) === s;
};